using System;
using System.Configuration;
using System.Data;
using digit.Core;

namespace SMS.ServiceManager
{
    public class ServiceOthersManager
    {
        #region CONSTRUCTORS
        static ServiceOthersManager()
        {
            _data = new ServiceOthersData(Util.GetConnectionString("SMSSERVICE"));
            _error = "";
        }
        #endregion

        #region ATTRIBUTES
        private static ServiceOthersData _data;
        private static string _error;
        #endregion

        #region PROPERTIES
        public static string ErrorMessage
        {
            get
            {
                return _error;
            }
        }

        #endregion

        #region METHODS
        public static bool Insert(string cmd, string code, string param, string content1, string content2, string content3, string content4, string content5, string serviceID, byte contentType, byte msgType, byte totalMsg, string createdBy, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[15];
                values[0] = Util.ReplaceNullTo(cmd, DBNull.Value);
                values[1] = Util.ReplaceNullTo(code, DBNull.Value);
                values[2] = Util.ReplaceNullTo(param, DBNull.Value);
                values[3] = Util.ReplaceNullTo(content1, DBNull.Value);
                values[4] = Util.ReplaceNullTo(content2, DBNull.Value);
                values[5] = Util.ReplaceNullTo(content3, DBNull.Value);
                values[6] = Util.ReplaceNullTo(content4, DBNull.Value);
                values[7] = Util.ReplaceNullTo(content5, DBNull.Value);
                values[8] = Util.ReplaceNullTo(serviceID, DBNull.Value);
                values[9] = Util.ReplaceNullTo(contentType, DBNull.Value);
                values[10] = Util.ReplaceNullTo(msgType, DBNull.Value);
                values[11] = Util.ReplaceNullTo(totalMsg, DBNull.Value);
                values[12] = Util.ReplaceNullTo(createdBy, DBNull.Value);
                values[13] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[14] = Util.ReplaceNullTo(status, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Insert(ServiceOthersInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[15];
                values[0] = Util.ReplaceNullTo(info.Cmd, DBNull.Value);
                values[1] = Util.ReplaceNullTo(info.Code, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.Param, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.Content1, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.Content2, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.Content3, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.Content4, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.Content5, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.ServiceID, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.ContentType, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.MsgType, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.TotalMsg, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.CreatedBy, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[14] = Util.ReplaceNullTo(info.Status, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(int serviceOtherID, string cmd, string code, string param, string content1, string content2, string content3, string content4, string content5, string serviceID, byte contentType, byte msgType, byte totalMsg, string createdBy, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[16];
                values[0] = serviceOtherID;
                values[1] = Util.ReplaceNullTo(cmd, DBNull.Value);
                values[2] = Util.ReplaceNullTo(code, DBNull.Value);
                values[3] = Util.ReplaceNullTo(param, DBNull.Value);
                values[4] = Util.ReplaceNullTo(content1, DBNull.Value);
                values[5] = Util.ReplaceNullTo(content2, DBNull.Value);
                values[6] = Util.ReplaceNullTo(content3, DBNull.Value);
                values[7] = Util.ReplaceNullTo(content4, DBNull.Value);
                values[8] = Util.ReplaceNullTo(content5, DBNull.Value);
                values[9] = Util.ReplaceNullTo(serviceID, DBNull.Value);
                values[10] = Util.ReplaceNullTo(contentType, DBNull.Value);
                values[11] = Util.ReplaceNullTo(msgType, DBNull.Value);
                values[12] = Util.ReplaceNullTo(totalMsg, DBNull.Value);
                values[13] = Util.ReplaceNullTo(createdBy, DBNull.Value);
                values[14] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[15] = Util.ReplaceNullTo(status, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(ServiceOthersInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[16];
                values[0] = info.ServiceOtherID;
                values[1] = Util.ReplaceNullTo(info.Cmd, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.Code, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.Param, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.Content1, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.Content2, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.Content3, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.Content4, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.Content5, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.ServiceID, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.ContentType, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.MsgType, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.TotalMsg, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.CreatedBy, DBNull.Value);
                values[14] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[15] = Util.ReplaceNullTo(info.Status, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(int serviceOtherID)
        {
            _error = "";
            try
            {
                object[] values = { serviceOtherID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(ServiceOthersInfo info)
        {
            _error = "";
            try
            {
                object[] values = { info.ServiceOtherID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static ServiceOthersInfo Select(int serviceOtherID)
        {
            _error = "";
            try
            {
                object[] values = { serviceOtherID };
                DataTable dTable = _data.Select(values);
                if (dTable.Rows.Count < 1) return null;


                ServiceOthersInfo info = new ServiceOthersInfo(dTable.Rows[0]);
                return info;
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAll()
        {
            _error = "";
            try
            {
                return _data.SelectAll();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SearchInfo(string Key)
        {
            _error = "";
            try
            {
                return _data.SearchInfo(Key);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }
        #endregion

    }
}